import datetime

from django.contrib.auth import admin
from django.db import models
from django.utils import timezone


class Devices(models.Model):
    device = models.IntegerField(default=0)  # 设备 ID
    alarm = models.IntegerField(default=0)  # 警告状态
    battery = models.IntegerField(default=1)  # 剩余电量
    value_speed = models.IntegerField(default=0)  # 滴速
    value_cap = models.IntegerField(default=0)  # 剩余液量
    value_time = models.IntegerField(default=999)  # 剩余时间
    bednum = models.CharField(default='0', max_length=45)  # 病患床号
    init_cap = models.IntegerField(default=0)  # 输液规格
    init_factor = models.FloatField(default=0)  # 滴系数
    init_speed = models.IntegerField(default=0)  # 最佳滴速
    init_time = models.TimeField(default=timezone.now)  # 注册时间
    is_init=models.IntegerField(default=0) #是否注册
    alarm_time = models.TimeField(default=timezone.now)  # 报警时间


class UserArea(admin.User):
    aid = models.IntegerField(default=0)


class Bed(models.Model):
    aid = models.IntegerField(default=0)  # 归属病区
    desc = models.TextField(default=0)  # 描述
    bed_id = models.CharField(default='0', max_length=45)  # 床号


class Area(models.Model):
    name = models.CharField(max_length=256, default="")  # 病区名称


class SystemLog(models.Model):
    action = models.CharField(max_length=1024, default="")  # 操作类型
    uid = models.IntegerField(default=0)  # 操作用户id
    action_date = models.DateTimeField(auto_now_add=True)  # 操作日期
    action_object = models.CharField(default="", max_length=255)  # 操作对象
    action_level = models.CharField(default="normal", max_length=16)  # 操作等级


def LogRuntimeInfo(uid, action, action_object, action_level=0, action_date=None):
    SystemLog.objects.create(action=action, uid=uid, action_object=action_object, action_level=action_level,
                             action_date=datetime.datetime.now())
